<template>
  <div id="taskArticficialSche" v-loading="loading">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('ex.taskarticficial')"
      @AdjustSelected="AdjustSelected"
      @Assignuser="Assignuser"
    ></v-tableTitle>
    <v-table
      :hasEdit="false"
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @upData="getTableData"
      ref="table"
    ></v-table>
    <el-dialog
      :title="$t('ex.Assignuser')"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      width="20%"
    >
      <!-- <el-row>
          <el-col :span="6"
                  style="height:40px;line-height: 40px">
            员工号:
          </el-col>
          <el-col :span="18">
            <el-input v-model="rtxuserkey"
                      placeholder=""></el-input>
          </el-col>
        </el-row> -->
      <el-input
        class="filter-input"
        placeholder=""
        v-model="filterText"
        clearable
        suffix-icon="el-icon-search"
      >
      </el-input>
      <el-table
        :data="tableData1"
        :height="300"
        @row-click="rowClick"
        highlight-current-row
      >
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column prop="fullname" :label="$t('app.fullname')" align="center">
        </el-table-column>
        <el-table-column prop="username" :label="$t('common.user')" align="center">
        </el-table-column>
      </el-table>

      <span slot="footer">
        <el-button type="primary" :disabled="!this.btnPermNameList.includes('WM06010403')" @click="defineClick"
          >{{$t('common.confirm')}}</el-button
        >
        <el-button @click="dialogVisible = false" :disabled="!this.btnPermNameList.includes('WM06010404')">{{$t('common.cancel')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import input from "commons/Detail"
import { queryAllUserList } from '@/api/system/config';

export default {
    name: "taskArticficialSche",
    mixins: [baseMixin, config],
    data() {
        return {
            loading: false,
            tableConfig: [
                {
                    label: this.$t('outbound.permissiontype'),
                    prop: "tasktype",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TASKTYPE")
                },
                {
                    label: this.$t('common.status'),
                    prop: "status",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TMSTATUS")
                },
                {
                    label: this.$t('in.priority'),
                    prop: "priority",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TMPRIORITY")
                },
                {
                    label: this.$t('config.sku'),
                    prop: "sku",
                    input: "input"
                },
                {
                    label: this.$t('ex.sourcekey'),
                    prop: "sourcekey",
                    input: "input"
                },
                {
                    label: this.$t('config.num'),
                    prop: "qty",
                    input: "input"
                },
                {
                    label: this.$t('outbound.fromloc'),
                    prop: "fromloc",
                    input: "input",
                },
                {
                    label: this.$t('config.toLoc'),
                    prop: "toloc",
                    input: "input"
                },
                {
                    label: this.$t('in.fromid'),
                    prop: "fromid",
                    input: "input"
                },
                {
                    label: this.$t('in.toid'),
                    prop: "toid",
                    input: "input"
                },
                {
                    label: this.$t('ex.rtxiswcstask'),
                    prop: "rtxiswcstask",
                    input: "input"
                },
                {
                    label: this.$t('outbound.user'),
                    prop: "userkey",
                    input: "input"
                },
                {
                    label: this.$t('out.wavekey'),
                    prop: "wavekey",
                    input: "input"
                },
                {
                    label: this.$t('out.taskgroup'),
                    prop: "rtxtaskgrp",
                    input: "input"
                },
                {
                    label: this.$t('out.no'),
                    prop: "seqno",
                    input: "input"
                },
            ],
            tableData: [],
            pageSize: 10,
            page: 1,
            total: 0,
            tableSelectData: [],
            tableSearhData: {},
            dialogVisible: false,
            rtxuserkey: null,
            tableData1: [],
            filterText: '',
        };
    },
    computed: {
        btnConfig() {
            return [
                { label: this.$t('ex.AdjustSelected'), certigier: this.adjustSelectedStatus||!this.btnPermNameList.includes('WM06010401'), disabled: true, invalid: "AdjustSelected" },
                { label: this.$t('ex.Assignuser'), certigier: this.adjustSelectedStatus||!this.btnPermNameList.includes('WM06010402'), invalid: "Assignuser" },
            ]
        }
    },
    created() {
    },
    methods: {
        async AdjustSelected(data) {
            try {
                let res = await this.$api.post(`/updateTaskSeqno`, data);
                
                    this.$message.success(res.returnMgr);
                    let page = sessionStorage.getItem('page');
                    this.getTableData(page, this.tableSearhData);
                    
                
            } catch (e) {
                this.$message.error(e);
            }
        },
        rowClick(data, column, e) {
            this.rtxuserkey = data.username;
        },
        getUser() {
            queryAllUserList({}).then(res => {
                    this.tableData1 = res.data;
            })
        },
        Assignuser() {
            this.dialogVisible = true
        },
        defineClick() {
            if (this.rtxuserkey === '' || this.rtxuserkey === null) {
                this.$message.error(this.$t('msg.msg30'));
                this.rtxuserkey = null
                return;
            } else {
                this.$api.post(`/assignUser/` + this.rtxuserkey, this.tableSelectData).then(res => {
                    
                        this.$message.success(this.$t('msg.msg75'));
                        this.dialogVisible = false;
                        this.getTableData(1, this.tableSearhData);
                        this.$refs.table.delSelectData(this.tableSelectData);
                });
            }

        },
        //选中的内容
        selectData(data) {
            this.tableSelectData = data;
        },
        async getTableData(page, data) {
            try {
                this.loading = true;
                let res = await this.$api.post(`/queryTaskArtificialSche/${page}`, data);
                
                    this.tableData = res.page.list;
                    this.pageSize = res.page.pageSize;
                    this.page = res.page.curpage;
                    this.total = res.page.total;
                    this.updatePriorityStatus = this.tableData <= 0
                
            } catch (e) {
                this.$message.error(e);
            } finally {
                this.loading = false;
            }
        },
        //搜索的值
        searhData(data, up) {
            if (!up) {
                this.tableSearhData = data;
            } else {
                this.tableSearhData = data;
                this.getTableData(1, this.tableSearhData);
            }
        },
    },
    mounted() {
        
        this.$store.commit("setSkip", {});
        this.$store.commit("setNewFlag", false);
        this.$store.commit("setRouteData", {});
        this.getTableData(1, {});
        this.getUser();
    },
    watch: {
        tableSelectData(data) {
            if (this.permissionStatus) {
                this.adjustSelectedStatus = event.length <= 0;
            }
        },
        filterText(val) {
            if (val && val != null && val.length > 0) {
                queryAllUserList({ username: val }).then(res => {
                        this.tableData1 = res.data;
                    
                })
            }
            if (val === "") {
                this.getUser();
            }
        }
    },
    components: {
        "v-tableTitle": tableTitle,
        "v-table": table,
        "v-input": input
    }
};
</script>

<style scoped>
#taskArticficialSche {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
